package com.toolbox;

import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDate;
import java.util.List;

@Slf4j
public class HKWorkday2023 {

    public static final String sqlTemplate="INSERT INTO TBL_SYS_HK_TRADEDATE (ID, TRADECHANNEL, TRADEDATE, ISDELETED, CREATEDBYID, CREATEDTIME, LASTMODIFIEDBYID, LASTMODIFIEDTIME) VALUES (substr(sys_guid(),0,20), '香港', TO_DATE('${workday}', 'YYYY-MM-DD'), '0', 'admin', sysdate, 'admin', sysdate);";

    public static final List<String> holidays = Lists.newArrayList(
            "2023-01-02", "2023-01-23", "2023-01-24", "2023-01-25",
            "2023-04-05", "2023-04-07", "2023-04-08", "2023-04-10",
            "2023-05-01", "2023-05-26"
            , "2023-06-22"
            , "2023-07-01"
            , "2023-09-30"
            , "2023-10-02", "2023-10-23"
            , "2023-12-25", "2023-12-26"
    );

    public static void main(String[] args) {

        LocalDate day = LocalDate.ofYearDay(2023, 1);

        LocalDate endDay = LocalDate.ofYearDay(2024, 1);

        do {
            if (isWorkDay(day)) {
                System.out.println(sqlTemplate.replace("${workday}",day.toString()));
            }
            day = day.plusDays(1);
        } while (day.isBefore(endDay));

    }


    public static boolean isWorkDay(LocalDate date) {
        int dayOfWeek = date.getDayOfWeek().getValue();
        return !(dayOfWeek >= 6 || holidays.contains(date.toString()));
    }
}
